<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: new_category.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if(($_GET['cID']) && (!$_POST) ) {
	$category = $db->db_query("SELECT
									*
								FROM
									".TABLE_CATEGORIES." c, " .
									TABLE_CATEGORIES_DESCRIPTION." cd
								WHERE
									c.categories_id = cd.categories_id
								AND
									c.categories_id = '".$_GET['cID']."'");

	$cInfo = new objectInfo($category->fields);

} elseif ($_POST) {
	$cInfo = new objectInfo($_POST);
	$categories_name = $_POST['categories_name'];
	$categories_url_alias = $_POST['categories_url_alias'];
	$categories_heading_title = $_POST['categories_heading_title'];
	$categories_description = $_POST['categories_description'];
	$categories_pic_alt = $_POST['categories_pic_alt'];
	$categories_meta_title = $_POST['categories_meta_title'];
	$categories_meta_description = $_POST['categories_meta_description'];
	$categories_meta_description_2 = $_POST['categories_meta_description_2'];
	$categories_meta_keywords = $_POST['categories_meta_keywords'];

} else
	$cInfo = new objectInfo(array());

$languages = get_languages();

$text_new_or_edit = ($_GET['action']=='new_category') ? TEXT_INFO_HEADING_NEW_CATEGORY : TEXT_INFO_HEADING_EDIT_CATEGORY;
?>
<tr>
	<td colspan="2">
		<script type="text/javascript">
			$(function() {
				$('#tabs').tabs({fx:{opacity:'toggle'}});
			});
		</script>
		<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td class="pageHeading">
					<?php echo sprintf($text_new_or_edit, output_generated_category_path($current_category_id)); ?>
				</td>
			</tr>
		</table>
	</td>
</tr>
<tr>
	<td>
		<?php
			$form_action = ($_GET['cID']) ? 'update_category' : 'insert_category';
			echo draw_form('new_category', FILENAME_CATEGORIES, 'cPath='.$cPath.'&cID='.$_GET['cID'].'&action='.$form_action, 'post', 'enctype="multipart/form-data"');
		?>
			<table width="100%">
				<tr>
					<td align="right">
						<button type="submit" name="update_category" class="button" value="">
							<span class="button_disk-black">
								<?php echo BUTTON_SAVE; ?>
							</span>
						</button>
						<?php if(isset($_GET['cID'])) { ?>
							<button type="submit" name="apply_new_category" class="button" value="">
								<?php echo BUTTON_APPLY; ?>
							</button>
						<?php } ?>
						<button type="submit" name="save_new_category_and_more" class="button" value="">
							<span class="button_disk--plus-black">
								<?php echo BUTTON_SAVE_CAT_AND_AGAIN; ?>
							</span>
						</button>
						<button type="button" class="button" onclick="window.location.href='<?php echo href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&cID=' . $_GET['cID']); ?>'">
							<span class="button_door-open-in-black">
								<?php echo BUTTON_CANCEL; ?>
							</span>
						</button>					
					</td>
				</tr>
			</table>
			<table width="100%" cellpadding="5">
				<tr>
					<td width="50%" valign="top">
						<h3><?php echo TEXT_TAB_1; ?></h3>
						<table width="100%">
							<tr>
								<td class="main"><?php echo TEXT_EDIT_STATUS; ?>:</td>
								<td class="main"><?php echo draw_selection_field('status', 'checkbox', '1',$cInfo->categories_status==1 ? true : false); ?></td>
							</tr>
							<tr>
								<td class="main">in welche Kategorie Box?: <?php echo get_help(34, 'Multikategorieboxen') ?></td>
								<td class="main"><?php echo draw_pull_down_menu('num', get_categories_box(), $cInfo->num); ?></td>
							</tr>
							<tr>
								<?php
								$files = array();
								if ($dir = opendir(DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/module/categorie_listing/')) {
									while (($file = readdir($dir)) !==false)
										if(is_file( DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/module/categorie_listing/'.$file) && ($file !="index.html"))
											$files[] = array('id' => $file, 'text' => $file);
									closedir($dir);
								}
								$default_array = array();
								if ($content['content_file']=='') {
									$default_array[] = array('id' => 'default','text' => TEXT_SELECT);
									$default_value = $cInfo->categories_template;
									$files = array_merge($default_array,$files);
								} else {
									$default_array[] = array('id' => 'default','text' => TEXT_NO_FILE);
									$default_value = $cInfo->categories_template;
									$files = array_merge($default_array,$files);
								} ?>
								<td class="main"><?php echo TEXT_CHOOSE_INFO_TEMPLATE_CATEGORIE ?></td>
								<td class="main"><?php echo draw_pull_down_menu('categories_template',$files,$default_value) ?></td>
							</tr>
							<tr>
								<?php
								$order_array = '';
								$order_array = array(array('id' => 'p.products_price','text'=>TXT_PRICES),
			  										array('id' => 'pd.products_name','text'=>TXT_NAME),
			  										array('id' => 'p.products_ordered','text'=>TXT_ORDERED),
			  										array('id' => 'p.products_sort','text'=>TXT_SORT),
													array('id' => 'p.products_date_added','text'=>TXT_AGE),
			  										array('id' => 'p.products_weight','text'=>TXT_WEIGHT),
			  										array('id' => 'p.products_quantity','text'=>TXT_QTY));
								$default_value = 'pd.products_name';
								
								$order_array_2 = '';
								$order_array_2 = array(array('id' => 'ASC', 'text'=>'aufsteigend'), 
														array('id' => 'DESC', 'text'=>'absteigend'));
								?>
								<td class="main"><?php echo TEXT_EDIT_PRODUCT_SORT_ORDER; ?>:</td>
								<td class="main">
									<?php 
										echo draw_pull_down_menu('products_sorting', $order_array, $cInfo->products_sorting).'<br />';
										echo draw_pull_down_menu('products_sorting2',$order_array_2,$cInfo->products_sorting2);
									?>
								</td>
							</tr>
							<tr>
								<td class="main"><?php echo TEXT_EDIT_SORT_ORDER; ?></td>
								<td class="main"><?php echo draw_input_field('sort_order', $cInfo->sort_order, 'size="2"'); ?></td>
							</tr>
							<tr>
								<td class="main"><?php echo TEXT_DEFAULT_LIST; ?></td>
								<td class="main">
									<?php
										$list = array(array('id' => 'product_listing_grid','text' => 'Gallerieansicht'), 
														array('id' => 'product_listing_list','text' => 'Listenansicht'),
														array('id' => 'product_listing_mosaic','text' => 'Mosaik-Darstellung'));
										echo draw_pull_down_menu('category_default_list', $list, $cInfo->category_default_list);
									?>
								</td>
							</tr>
							<tr>
								<td class="main" valign="top">
									Welche Spalten des Templates sollen dargestellt werden?
								</td>
						        <td class="main">
									<?php
										echo image('images/template_prod.gif', 'Kategorie Seite' , 'align="right"').'<br />';
										
										if(isset($_GET['cID'])) {
											echo draw_selection_field('categories_col_top', 'checkbox', '1', $cInfo->categories_col_top==1 ? true : false).' 1 oben<br />';
											echo draw_selection_field('categories_col_left', 'checkbox', '1', $cInfo->categories_col_left==1 ? true : false).' 2 linke Spalte<br />';
											echo draw_selection_field('categories_col_right', 'checkbox', '1', $cInfo->categories_col_right==1 ? true : false).' 3 rechte Spalte<br />';
											echo draw_selection_field('categories_col_bottom', 'checkbox', '1', $cInfo->categories_col_bottom==1 ? true : false).' 4 unten<br />';
										} else {
											echo draw_selection_field('categories_col_top', 'checkbox', '1', (GLOBAL_COLUMN_TOP == 1 ? true : false)).' 1 oben<br />';
											echo draw_selection_field('categories_col_left', 'checkbox', '1', (GLOBAL_COLUMN_LEFT == 1 ? true : false)).' 2 linke Spalte<br />';
											echo draw_selection_field('categories_col_right', 'checkbox', '1', (GLOBAL_COLUMN_RIGHT == 1 ? true : false)).' 3 rechte Spalte<br />';
											echo draw_selection_field('categories_col_bottom', 'checkbox', '1', (GLOBAL_COLUMN_BOTTOM == 1 ? true : false)).' 4 unten<br />';
										}
									?>
								</td>
							</tr>
						</table>
					</td>
					<td valign="top" style="border-left: 1px dashed #ccc">
						<h3>Kategorie Bild</h3>
						<table width="100%" border="0">
							<tr>
								<td class="main" width="200" valign="top">
								<?php if ($cInfo->categories_image) { ?>
									<img class="categories_img" src="<?php echo DIR_WS_CATALOG.'images/categories/'.$cInfo->categories_image; ?>" alt="" />
								<?php } ?>
								</td>
								<td class="main">
									<table width="100%">
										<tr>
											<td class="main">Bild suchen:</td>
											<td class="main">
												<?php echo  draw_file_field('categories_image').draw_hidden_field('categories_previous_image', $cInfo->categories_image); ?>
											</td>
										</tr>
										<?php for ($i=0; $i<sizeof($languages); $i++) { ?>
										<tr>
											<td class="main">Alternativtext:</td>
											<td class="main">
												<?php echo image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('categories_pic_alt['.$languages[$i]['id'].']',(($categories_pic_alt[$languages[$i]['id']]) ? stripslashes($categories_pic_alt[$languages[$i]['id']]) : get_categories_pic_alt($cInfo->categories_id, $languages[$i]['id'])), 'size=30'); ?>
											</td>
										</tr>
										<?php } if ($cInfo->categories_image) { ?>
											<tr>
												<td class="main">&nbsp;</td>
												<td class="main">
													<?php echo $cInfo->categories_image. '&nbsp;' .draw_selection_field('del_cat_pic', 'checkbox', 'yes').TEXT_DELETE; ?>
												</td>
											</tr>
										<?php } ?>
									</table>
								</td>
							</tr>
							<?php
								if(GROUP_CHECK == 'true') {
									$customers_statuses_array = get_customers_statuses();
									$customers_statuses_array = array_merge(array(array('id'=>'all','text'=>TXT_ALL)),$customers_statuses_array);
									?>
									<tr>
										<td style="border: 1px solid #b20000; border-width: 1px 0 1px 1px; background:#FFE9A6" valign="top">
											<?php echo ENTRY_CUSTOMERS_STATUS; ?>
										</td>
										<td style="border: 1px solid #b20000; border-width: 1px 1px 1px 0; background:#FFE9A6">
											<?php
											for($i=0;$n=sizeof($customers_statuses_array),$i<$n;$i++) {
												if($category->fields['group_permission_'.$customers_statuses_array[$i]['id']] == 1)
													$checked='checked ';
												else
													$checked='';
												echo '<input type="checkbox" name="groups[]" value="'.$customers_statuses_array[$i]['id'].'"'.$checked.'> '.$customers_statuses_array[$i]['text'].'<br />';
											}
											?>
										</td>
									</tr>
							<?php } ?>
						</table>
					</td>
				</tr>
			</table>
				<div id="tabs">
					<ul>
						<?php for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
							<li>
								<a href="#language_<?php echo $languages[$i]['id']; ?>" onclick="javascript:void(0);">
									<span> <?php echo image('../lang/'.$languages[$i]['directory'].'/'.$languages[$i]['image'], $languages[$i]['name']).' '.$languages[$i]['name']; ?></span>
								</a>
							</li>
						<?php } ?>
					</ul>
					<?php for ($i=0; $i<sizeof($languages); $i++) { ?>
						<div id="language_<?php echo $languages[$i]['id']; ?>">
							<table width="100%" border="0">
								<tr>
									<td class="main"><?php echo TEXT_EDIT_CATEGORIES_NAME; ?></td>
									<td class="main">
										<?php echo image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('categories_name['.$languages[$i]['id'].']', (($categories_name[$languages[$i]['id']]) ? stripslashes($categories_name[$languages[$i]['id']]) : get_categories_name($cInfo->categories_id, $languages[$i]['id'])),'size=60'); ?>
									</td>
								</tr>
								<tr>
						            <td class="main">URL Alias:</td>
						            <td class="main"><?php echo image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('categories_url_alias['.$languages[$i]['id'].']', (($categories_url_alias[$languages[$i]['id']]) ? stripslashes($categories_url_alias[$languages[$i]['id']]) : get_categories_url_alias($cInfo->categories_id, $languages[$i]['id'])),'size=60').' <a href="#" onclick="javascript:return false;"'.mouseOverJS(HEAD_URL_ALIAS,BODY_URL_ALIAS).'>'.image(DIR_WS_ICONS.'icon_help.gif').'</a>'; ?></td>
						          </tr>
								<tr>
									<td class="main"><?php echo TEXT_EDIT_CATEGORIES_HEADING_TITLE; ?></td>
									<td class="main">
										<?php echo image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']).'&nbsp;'.draw_input_field('categories_heading_title['.$languages[$i]['id'].']', (($categories_name[$languages[$i]['id']]) ? stripslashes($categories_name[$languages[$i]['id']]) : get_categories_heading_title($cInfo->categories_id, $languages[$i]['id'])),'size=60'); ?>
									</td>
								</tr>
								<tr>
									<td class="main" valign="top"><?php  echo TEXT_EDIT_CATEGORIES_DESCRIPTION; ?></td>
									<td class="main" valign="top">
										<?php echo wysiwyg('categories_description_'.$languages[$i]['id'], (($categories_description[$languages[$i]['id']]) ? stripslashes($categories_description[$languages[$i]['id']]) : get_categories_description($cInfo->categories_id, $languages[$i]['id']))) ?>
									</td>
								</tr>
								<tr>
									<td class="main" valign="top">untere <?php  echo TEXT_EDIT_CATEGORIES_DESCRIPTION; ?></td>
									<td class="main" valign="top">
										<?php echo wysiwyg('categories_description_2_'.$languages[$i]['id'], (($categories_description_2[$languages[$i]['id']]) ? stripslashes($categories_description_2[$languages[$i]['id']]) : get_categories_description_2($cInfo->categories_id, $languages[$i]['id']))) ?>
									</td>
								</tr>
								<tr>
									<td class="main" valign="top"><?php  echo TEXT_META_TITLE; ?></td>
									<td class="main" valign="middle">
										<?php echo image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']); ?>&nbsp;
										<?php echo draw_input_field('categories_meta_title['.$languages[$i]['id'].']',(($categories_meta_title[$languages[$i]['id']]) ? stripslashes($categories_meta_title[$languages[$i]['id']]) : get_categories_meta_title($cInfo->categories_id, $languages[$i]['id'])), 'size=50'); ?>
									</td>
								</tr>
								<tr>
									<td class="main" valign="top"><?php  echo TEXT_META_DESCRIPTION; ?></td>
									<td class="main" valign="middle">
										<?php echo image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']); ?>&nbsp;
										<?php echo draw_input_field('categories_meta_description['.$languages[$i]['id'].']', (($categories_meta_description[$languages[$i]['id']]) ? stripslashes($categories_meta_description[$languages[$i]['id']]) : get_categories_meta_description($cInfo->categories_id, $languages[$i]['id'])),'size=50'); ?>
								</td>
							</tr>
							<tr>
								<td class="main" valign="top"><?php  echo TEXT_META_KEYWORDS; ?></td>
								<td class="main" valign="middle">
									<?php echo image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']); ?>&nbsp;
									<?php echo draw_input_field('categories_meta_keywords['.$languages[$i]['id'].']',(($categories_meta_keywords[$languages[$i]['id']]) ? stripslashes($categories_meta_keywords[$languages[$i]['id']]) : get_categories_meta_keywords($cInfo->categories_id, $languages[$i]['id'])),'size=50'); ?>
								</td>
							</tr>
						</table>
						<?php if(TREEPODIA_STATUS == 'true') { ?>
							<br /><h3>Treepodia</h3>
							<table width="100%">
								<?php for($t = 1; $t < 6; $t++) { ?>
									<tr>
										<td class="main" valign="top" width="1"><nobr>Artikel-Beschreibung <?php echo $t; ?>:</nobr></td>
										<td class="main" valign="middle">
											<?php echo image(DIR_WS_LANGUAGES.$languages[$i]['directory'].'/admin/images/'.$languages[$i]['image']); ?>&nbsp;
											<?php echo get_categories_treepodia($cInfo->categories_id, $t, $languages[$i]['id']) ?>
										</td>
									</tr>
								<?php } ?>
							</table>
						<?php } ?>
					</div>
				<?php } ?>
			</div>
			<?php echo draw_hidden_field('categories_date_added', (($cInfo->date_added) ? $cInfo->date_added : date('Y-m-d'))).draw_hidden_field('parent_id', $cInfo->parent_id); ?>
			<?php echo draw_hidden_field('categories_id', $cInfo->categories_id); ?>
		</form>
	</td>
</tr>